/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.InfoDAO;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.PreparedSentence;
import com.openbravo.data.loader.SerializerWriteString;
import com.openbravo.data.loader.StaticSentence;
import com.openbravo.bean.infobean.UserInfo;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class UserInfoDAO extends InfoDAO<UserInfo,UserDAO>{

    public UserInfoDAO(UserDAO base) {
        super(base,new int[]{0,1});
    }

    public UserInfo readValues(DataRead dr,UserInfo obj) throws BasicException {
        if(obj==null)
        	obj=new UserInfo();
        obj.setM_sId(dr.getString(1));
        obj.setM_sName(dr.getString(2));
    	return obj;
    }

    public UserInfo loadPeopleByID(String userId) throws BasicException {
        return (UserInfo) new StaticSentence(s, "SELECT ID, NAME FROM PEOPLE WHERE ID = ?", SerializerWriteString.INSTANCE, this).find(userId);
    }

    public final UserInfo findPeopleByCard(String card) throws BasicException {
        return (UserInfo) new PreparedSentence(s, "SELECT ID, NAME FROM PEOPLE WHERE CARD = ? AND VISIBLE = " + s.getDB().TRUE(), SerializerWriteString.INSTANCE, this).find(card);
    }

    public final UserInfo findPeopleByName(String name) throws BasicException {
        return (UserInfo) new PreparedSentence(s, "SELECT ID, NAME FROM PEOPLE WHERE NAME = ? AND VISIBLE = " + s.getDB().TRUE(), SerializerWriteString.INSTANCE, this).find(name);
    }

    public final List listPeopleVisible() throws BasicException {
        return new StaticSentence(s, "SELECT ID, NAME FROM PEOPLE WHERE VISIBLE = " + s.getDB().TRUE(), null, this).list();
    }

    @Override
    public List<UserInfo> list() throws BasicException {
         return new StaticSentence(s, "SELECT ID, NAME FROM PEOPLE ORDER BY NAME", null, this).list();
    }

    @Override
    public Class getSuportClass() {
        return UserInfo.class;
    }
}

